<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登录-{APP_NAME}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="{RESOURCES_PATH}/layui/css/layui.css">
    <style type="text/css">
        body{
            max-width: 600px;
            margin: 20px auto;
        }
        a{
            color: #3498DB;
            text-decoration: none;
        }
        img{
            max-width: 100%;
        }

        h1,h2,h3{
            font-weight: 400;
            margin: 0;
        }

        * {
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
        }
        .title{
            font-size: 25px;
            text-align: center;
            margin: 60px 0 40px 0;
        }
        .layui-form-label {
            color: black;
        }
    </style>
</head>
<body>

<h1 class="title">登录</h1>

<blockquote class="layui-elem-quote layui-text">
    <p>如需要使用请<a href="https://gitee.com/yangdongge/MarkdownNote">自行搭建</a>。</p>
</blockquote>


<form class="layui-form" action="" lay-filter="register">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username" lay-verify="username" autocomplete="on" placeholder="请输入用户名" class="layui-input" autofocus="autofocus">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input id="password" type="password" name="password" lay-verify="password" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-fluid" lay-submit="" lay-filter="demo1">立即提交</button>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <p style="text-align: center;"><a href="{url(['mod' => 'site','act' => 'register'])}">注册</a></p>
        </div>
    </div>
</form>

<script type="text/javascript">
    var SITE_URL = '{SITE_URL}';
</script>
<script src="{RESOURCES_PATH}/layui/layui.js" charset="utf-8"></script>

<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script type="text/javascript">
    layui.use(['form'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,$ = layui.$;

        //自定义验证规则
        form.verify({
            username: function(value){
                if(value.length < 5){
                    return '用户名至少得6个字符啊';
                }
            }
            ,password: [/(.+){6,12}$/, '密码必须6到12位']
        });

        //监听提交
        form.on('submit(demo1)', function(data){
            $.post("{url(['mod' => 'site', 'act' => 'login'])}", data.field, function (data) {
                if (data.code === 200) {
                    localStorage.setItem('token', data.data.token);
                    layer.confirm(data.msg, function () {
                        window.location.href = "{url()}";
                    });
                }else {
                    layer.msg(data.msg);
                    return false;
                }
            }, 'json');
            return false;
        });
    });
</script>

</body>
</html>